home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / netlib / Net_MakeInetAddr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-21  |  1.5 KB  |  61 lines

  1. /* 
  2.  * Net_MakeInetAddr.c --
  3.  *
  4.  *    Create an internet address from a host and network number.
  5.  *
  6.  * Copyright 1987 Regents of the University of California
  7.  * All rights reserved.
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifndef lint
  18. static char rcsid[] = "$Header: /sprite/src/lib/net/RCS/Net_MakeInetAddr.c,v 1.1 88/11/21 09:10:19 mendel Exp $ SPRITE (Berkeley)";
  19. #endif not lint
  20.  
  21.  
  22. #include "sprite.h"
  23. #include "net.h"
  24.  
  25.  
  26. /*
  27.  *----------------------------------------------------------------------
  28.  *
  29.  * Net_MakeInetAddr --
  30.  *
  31.  *    Formulate an Internet address from network and host numbers.  
  32.  *
  33.  * Results:
  34.  *    An IP address.
  35.  *
  36.  * Side effects:
  37.  *    None.
  38.  *
  39.  *----------------------------------------------------------------------
  40.  */
  41.  
  42. Net_InetAddress
  43. Net_MakeInetAddr(net, host)
  44.     unsigned int net, host;
  45. {
  46.     Net_InetAddress addr;
  47.  
  48.     if (net < 128) {
  49.     addr =(net << NET_INET_CLASS_A_SHIFT) | 
  50.                 (host & NET_INET_CLASS_A_HOST_MASK);
  51.     } else if (net < 65536) {
  52.     addr =(net << NET_INET_CLASS_B_SHIFT) | 
  53.                 (host & NET_INET_CLASS_B_HOST_MASK);
  54.     } else {
  55.     addr =(net << NET_INET_CLASS_C_SHIFT) | 
  56.                 (host & NET_INET_CLASS_C_HOST_MASK);
  57.     }
  58.     return(Net_HostToNetInt(addr));
  59. }
  60.  
  61.